{"componentChunkName":"component---src-templates-blog-post-js","path":"/Data Structure/binary-search-tree/","result":{"data":{"site":{"siteMetadata":{"title":"Tory","author":"[Tory]","siteUrl":"https://gatsby-starter-bee.netlify.com","comment":{"disqusShortName":"","utterances":"JaeYeopHan/gatsby-starter-bee"},"sponsor":{"buyMeACoffeeId":"jbee"}}},"markdownRemark":{"id":"6de6e08f-623b-52c6-994f-795c054f5240","excerpt":"Jump into BST 이진트리 구조에 특수한 규칙을 적용한 트리입니다. 부모 노드를 기준으로 왼쪽 자식 노드에는 작은 값의 노드가 삽입되고, 오른쪽 자식 노드에는 큰 값이 삽입 됩니다. Basic aspects of BST: 좌우의 균형이 맞으면, 탐색, 삽입, 제거의 시간복잡도가 log(n)으로 상당히 빠른 편에 속한다. 삽입되는 순서에 따라 트리가 달라진다. 한쪽으로 치우친 skewed Tree 형태가 되면, 탐색, 삽입, 제거의 시간복잡도가 o(n…","html":"<h1 id=\"jump-into-bst\" style=\"position:relative;\"><a href=\"#jump-into-bst\" aria-label=\"jump into bst permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Jump into BST</h1>\n<p>이진트리 구조에 특수한 규칙을 적용한 트리입니다. 부모 노드를 기준으로 왼쪽 자식 노드에는 작은 값의 노드가 삽입되고, 오른쪽 자식 노드에는 큰 값이 삽입 됩니다.</p>\n<h2 id=\"basic-aspects-of-bst\" style=\"position:relative;\"><a href=\"#basic-aspects-of-bst\" aria-label=\"basic aspects of bst permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Basic aspects of BST:</h2>\n<ol>\n<li>좌우의 균형이 맞으면, 탐색, 삽입, 제거의 시간복잡도가 log(n)으로 상당히 빠른 편에 속한다.</li>\n<li>삽입되는 순서에 따라 트리가 달라진다.</li>\n<li>한쪽으로 치우친 skewed Tree 형태가 되면, 탐색, 삽입, 제거의 시간복잡도가 o(n)이 된다.</li>\n<li>숫자가 삽입된 노드를 기준으로 왼쪽 서브 트리에는 기준 값보다 모두 작은 값을 가진 노드가 있으며, 반대로 오른쪽에는 큰 값을 가진 노드만이 연결된다.</li>\n<li>자료의 중복이 허용되지 않는다.</li>\n</ol>\n<h2 id=\"method\" style=\"position:relative;\"><a href=\"#method\" aria-label=\"method permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Method:</h2>\n<h3 id=\"탐색-logn\" style=\"position:relative;\"><a href=\"#%ED%83%90%EC%83%89-logn\" aria-label=\"탐색 logn permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>탐색: log(n)</h3>\n<ul>\n<li>루트 노드를 기준으로 찾고자하는 값과 대소 관계를 파악한다.(탐색 시작)</li>\n<li>같은 값을 가진 노드가 발견되면, <code class=\"language-text\">True</code> 를 리턴한다.</li>\n<li>찾고자 하는 값이 노드의 값보다 작으면 왼쪽 노드로 이동한다.</li>\n<li>찾고자 하는 값이 노드의 값보다 크면 오른쪽 노드로 이동한다.</li>\n<li>더 이상 내려 갈 수 없는 마지막 노드에 도달하면 <code class=\"language-text\">False</code>를 반환한다.</li>\n</ul>\n<h3 id=\"삽입-logn\" style=\"position:relative;\"><a href=\"#%EC%82%BD%EC%9E%85-logn\" aria-label=\"삽입 logn permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>삽입: log(n)</h3>\n<ul>\n<li>탐색과 같이 루트 노드를 기준으로 값의 대소관계를 가려 더 이상 아래로 이동할 수 없는 노드까지 도달하면 그 자리에 삽입한다.(부모노드와, 부모노드에서 이동된 방향 필요)\n<strong>note:</strong> 단, 같은 값이 발견되면 즉시 False를 반환한다.</li>\n</ul>\n<h3 id=\"제거-logn\" style=\"position:relative;\"><a href=\"#%EC%A0%9C%EA%B1%B0-logn\" aria-label=\"제거 logn permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>제거: log(n)</h3>\n<ul>\n<li>case 1. 제거하고자하는 노드가 자식 노드를 가지고 있지 않은 경우 => <code class=\"language-text\">부모 노드와의 연결을 끊는다.</code></li>\n<li>\n<p>case 2. 제거하고자하는 노드가 한 개의 자식 노드를 가지고 있는 경우 => <code class=\"language-text\">부모 노드와 자식노드의 자식노드를 연결한다.</code></p>\n<ul>\n<li>부모노드에서 연결된 방향과 자식노드에서 연결된 자식노드의 방향을 고려해서 총 4가지의 경우가 생긴다.</li>\n</ul>\n</li>\n<li>case 3. 제거하고자하는 노드가 두 개의 자식 노드를 가지고 있는 경우 => <code class=\"language-text\">제거하려는 노드의 오른쪽 서브 트리에서 가장 작은 값을 가진 노드로 대체 or 제거하려는 노드의 왼쪽 서브 트리에서 가작 큰 값을 가진 노드로 대체한다.</code></li>\n</ul>","frontmatter":{"title":"Binary Search Tree","date":"April 05, 2021"}}},"pageContext":{"slug":"/Data Structure/binary-search-tree/","previous":{"fields":{"slug":"/algorithm/merge-sort/"},"frontmatter":{"title":"Merge Sort","category":"algorithm","draft":false}},"next":{"fields":{"slug":"/html/til210406/"},"frontmatter":{"title":"TIL210406","category":"html","draft":false}}}},"staticQueryHashes":["3128451518","521680639"]}